package com.koron.operation.classes.form.bean.dto;

import cn.hutool.core.collection.CollUtil;
import com.koron.operation.classes.form.bean.po.ClassesFormRow;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;
import java.util.Objects;

/**
 * @author jzp
 * @since 2023/5/18
 */
@EqualsAndHashCode(callSuper = true)
@Data
@ApiModel(value = "月度排班表行数据集", description = "ClassesFormRowDTO")
public class ClassesFormRowDTO extends ClassesFormRow {

    @ApiModelProperty("行数据")
    private List<ClassesFormShiftDTO> shiftList;

    @ApiModelProperty("本月计划总工时")
    private Double workHoursPlan;

    @ApiModelProperty("本月加班总工时")
    private Double workHoursOver;

    @ApiModelProperty("本月总工时")
    private Double workHoursTotal;

    public Double getWorkHoursPlan() {
        if (CollUtil.isEmpty(shiftList)) {
            return 0d;
        }
        workHoursPlan = shiftList.stream().map(ClassesFormShiftDTO::getPlanHours).filter(Objects::nonNull).reduce(Double::sum).orElse(0d);
        return workHoursPlan;
    }

    public Double getWorkHoursOver() {
        if (CollUtil.isEmpty(shiftList)) {
            return 0d;
        }
        workHoursOver = shiftList.stream().map(ClassesFormShiftDTO::getOverHours).filter(Objects::nonNull).reduce(Double::sum).orElse(0d);
        return workHoursOver;
    }

    public Double getWorkHoursTotal() {
        workHoursPlan = workHoursPlan == null ? getWorkHoursPlan() : workHoursPlan;
        workHoursOver = workHoursOver == null ? getWorkHoursOver() : workHoursOver;
        return workHoursPlan + workHoursOver;
    }
}
